<?php
/**
 * Conversations - A lightweight BB for Xaraya
 *
 * @package modules
 * @copyright (C) 2003-2006 The Digital Development Foundation.
 * @license GPL {@link http://www.gnu.org/licenses/gpl.html}
 * @link http://www.xaraya.com
 *
 * @subpackage conversations
 * @link http://xaraya.com/index.php/release/760.html
 * @author John Cox
*/
/**
 * Create a new lookup for tags to post
 * 
 * @package Xaraya eXtensible Management System
 * @copyright (C) 2005 by the Xaraya Development Team.
 * @license GPL {@link http://www.gnu.org/licenses/gpl.html}
 * @link http://www.xaraya.org
 *
 * @subpackage  xarbb Module
 * @author John Cox
*/
/**
 * create a new subscription
 * @param $args['tagid'] integer
 * @param $args['uid'] integer
 * @returns int
 * @return bool true / false
 */
function conversations_userapi_createsubs($args)
{
    extract($args);
    // Argument check - make sure that all required arguments are present,
    // if not then set an appropriate error message and return
    $invalid = array();
    if (!isset($tagid) || !is_numeric($tagid)) {
        $invalid[] = 'tagid';
    } 
    if (!isset($uid) || !is_numeric($uid)) {
        $invalid[] = 'uid';
    }
    if (count($invalid) > 0) {
        $msg = xarML('Invalid #(1)', join(', ', $invalid));
        xarErrorSet(XAR_SYSTEM_EXCEPTION, 'BAD_PARAM', new SystemException($msg));
        return;
    } 
    
    // Get datbase setup
    $dbconn =& xarDBGetConn();
    $xartable =& xarDBGetTables();
    $table = $xartable['csubs'];
    
    // Add item
    $query = "INSERT INTO $table ("
        . " xar_tagid, xar_uid)"
        . " VALUES (?, ?)";
    $result =& $dbconn->Execute($query, array($tagid, $uid));
    if (!$result) return;
    
    return true;
}
?>